package com.kaifa.org.tp04.example02;

import com.kaifa.org.tp04.example02.bean.User;
import com.kaifa.org.tp04.example02.dao.UserDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Test {
    public static void main(String[] args) {
        ApplicationContext ac =new ClassPathXmlApplicationContext("jdbc.xml");
        UserDao userDao= ac.getBean("userDao",UserDao.class);
        User us = new User();
        us.setUserName("admin");
        us.setUserPwd("123456");
        int i = userDao.addUser(us);
        if(i>0){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
        User us2 = new User();
        us2.setUserPwd("12345678");
        us2.setUserName("admin");
        us2.setId(1);
        int i2 = userDao.updateUser(us2);
        if(i2>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }

        List<User> userList=userDao.selectAllUser();
        for (User uss:userList) {
            System.out.println(uss);
        }
        User us3 = userDao.selectUserById(2);
        System.out.println(us3);

    }
}
